<?php
namespace app\admin\controller;
use think\Db;
use think\facade\Request;
use app\admin\model\Location as thisModel;
class Location extends Common
{
    function index(){
        $thisModel = new thisModel();
        $list = $thisModel->mainAllList();
        // dump($list);exit;

        $this->assign('list',$list);
        return $this->fetch('index');
    }

    function mainEdit(){
        $thisModel = new thisModel();
        if (request()->isAjax()) {
            $postData = input('post.');
            $id = input('post.id');
            $data = $thisModel->disposeData(input('post.'));
           // dump($data);exit;
            if($id > 0){
                $res = $thisModel->save($data,['id'=>$id]);
                if($res !== false){
                    exitjson(1, '保存成功');
                }else{
                    exitjson(0, '保存失败');
                }
            }else{
                $res = $thisModel->save($data);
                if ($res) {
                    exitjson(1, '保存成功');
                } else {
                    exitjson(0, '保存失败');
                }
            }
        } else {

            if(input('id') > 0){
                $one = $thisModel->get(input('id'));
                $this->assign('one',$one);
            }
//            dump($one);exit;
            return $this->fetch('mainEdit');
        }
    }

    function mainDel(){
        $id = input('id');
        if($id>0){
            $thisModel = new thisModel();
            $one = $thisModel->get($id);
            $res = $one->delete();
            if($res !== false){
                exitjson(1,'删除成功');
            }else{
                exitjson(0,'删除失败');
            }
        }
    }
}